<?php
class reseller
{
	public static function findCountryReseller()
	{
		$query="select country,count(*) from ccinfo where userid=0 and orderid=0 and site not in ('seller') group by country";
		$searhCountry=database::GetQueryResult($query,0,0);
		$line=null;
		foreach($searhCountry as $country)
		{
			$countryName=$country['country'];
			$arrCountry[]=$countryName;
		}
		return $arrCountry;
	}
	public static function findStateReseller($country)
	{
		$getState=database::LimitQuery("ccinfo",array(
		'select' => 'state',
		'condition' => array(
		'userid' => '0',
		'orderid' => '0',
		'country' => $country,
		),
		'groupby' => ' group by state'
		));
		$line=NULL;
		foreach($getState as $state)
		{
			$variable=$state['state'];
			$stateX=strtoupper($variable);
			$stateValue=strtolower($variable);
			$line='<option value="'.$stateValue.'">'.$stateX.'</option>'.$line;
		}
		return $line;
	}
	public static function findTypeReseller($country)
	{
		$getType=database::LimitQuery("ccinfo",array(
		'select' => 'typecc',
		'condition'=>array(
		'orderid' => '0',
		'userid' => '0',
		'country' => $country
		),
		'groupby' => 'group by  typecc'
		));
		$line=null;
		foreach($getType as $type)
		{
			$variable=$type["typecc"];
			$line='<option value="'.$variable.'">'.$variable.'</option>'.$line;
		}
		$lineFinal='<option value="" >All</option>'.$line;
		return $lineFinal;
	}
	public static function searchCcReseller($country,$type,$bin,$state,$dob,$ssn,$price)
	{
		$country=strtolower($country);
		$searchCc="select ccid,ccnumber,zip,firstname,exmonth,exyear,city,state,country from ccinfo where country='$country' ";
		if(!empty($type))
		{
			if($type==4)
			{
				$type="visa";
			}
			else if($type==5)
			{
				$type="master";
			}
			else if($type==3)
			{
				$type="amex";
			}
			else if($type==6)
			{
				$type="dis";
			}
			$searchCc=$searchCc."and typecc='$type' ";
		}
		if(!empty($bin))
		{
			$searchCc=$searchCc."and ccnumber like '".$bin."%' ";
		}
		if(!empty($state))
		{
			$searchCc=$searchCc."and state='$state' ";
		}
		if($dob=='yes')
		{
			$dob=strtolower($dob);
			$searchCc=$searchCc."and dob !=0 ";
		}
		if($ssn=='yes')
		{
			$ssn=strtolower($ssn);
			$searchCc=$searchCc."and ssn !=0 ";
		}
		$searchCc=$searchCc."and orderid=0 and userid=0 and site not in ('seller') order by rand() limit 0,40";
		$result=database::GetQueryResult($searchCc,0,0);
		$IdReturn=0;
		foreach($result as $ccInfo)
		{
			$bin=substr($ccInfo['ccnumber'],0,6);
			$name=rtrim(trim($ccInfo['firstname']));
			$ArrReturn["$IdReturn"]['bin']=$bin;
			$ArrReturn["$IdReturn"]['name']=$name;
			$ArrReturn["$IdReturn"]['exM']=rtrim(trim($ccInfo['exmonth']));
			$ArrReturn["$IdReturn"]['exY']=rtrim(trim($ccInfo['exyear']));
			$ArrReturn["$IdReturn"]['city']=rtrim(trim($ccInfo['city']));
			$ArrReturn["$IdReturn"]['state']=rtrim(trim($ccInfo['state']));
			$ArrReturn["$IdReturn"]['country']=rtrim(trim($ccInfo['country']));
			$ArrReturn["$IdReturn"]['zip']=rtrim(trim($ccInfo['zip']));
			$ArrReturn["$IdReturn"]['ccid']=rtrim(trim($ccInfo['ccid']));
			$ArrReturn["$IdReturn"]['price']=$price;
			$IdReturn++;
		}
		if(empty($ArrReturn))
		{
			return 0; 
		}
		else
		{
			return $ArrReturn;
		}
	
		
	}
	public static function checkoutReseller($ccIdList,$price,$userId,$orderId)
	{
		foreach($ccIdList as $ccArr)
		{
			$arrId[]=$ccArr;
		}
		$UpdateCc=database::Update('ccinfo',array(
		'ccid' => $arrId
		),array(
		'pricesell' => $price,
		'orderid' => $orderId,
		'userid' => $userId,
		'site' => 'partner',
		'status' => 'valid'
		));
		if($UpdateCc==true)
		{
			return true;
		}
		else
		{
			return 0;
		}
	}
}

?>